<template>
  <div class="menu-page">
    <el-card>
      <template #header>
        <div class="card-header">
          <span>菜单管理</span>
          <el-button type="primary" @click="handleAdd">
            <el-icon><Plus /></el-icon>
            新增菜单
          </el-button>
        </div>
      </template>

      <el-table
        :data="tableData"
        style="width: 100%"
        v-loading="loading"
        row-key="id"
        :tree-props="{ children: 'children' }"
      >
        <el-table-column prop="name" label="菜单名称" width="200" />
        <el-table-column prop="path" label="路由路径" />
        <el-table-column prop="icon" label="图标" width="100" />
        <el-table-column prop="sort" label="排序" width="80" />
        <el-table-column prop="type" label="类型" width="100">
          <template #default="{ row }">
            <el-tag :type="row.type === '菜单' ? 'success' : 'info'">
              {{ row.type }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200" fixed="right">
          <template #default="{ row }">
            <el-button type="primary" link size="small" @click="handleEdit(row)">
              编辑
            </el-button>
            <el-button type="danger" link size="small" @click="handleDelete(row)">
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'

const loading = ref(false)

const tableData = ref([
  {
    id: 1,
    name: '系统管理',
    path: '/system',
    icon: 'Setting',
    sort: 1,
    type: '目录',
    children: [
      {
        id: 11,
        name: '用户管理',
        path: '/system/user',
        icon: 'User',
        sort: 1,
        type: '菜单'
      },
      {
        id: 12,
        name: '权限管理',
        path: '/permissions',
        icon: 'Avatar',
        sort: 2,
        type: '菜单'
      }
    ]
  },
  {
    id: 2,
    name: '仪表盘',
    path: '/dashboard',
    icon: 'Odometer',
    sort: 0,
    type: '菜单'
  }
])

const handleAdd = () => {
  ElMessage.info('新增功能待实现')
}

const handleEdit = (row: any) => {
  ElMessage.info(`编辑菜单: ${row.name}`)
}

const handleDelete = (row: any) => {
  ElMessageBox.confirm(`确定要删除菜单 "${row.name}" 吗？`, '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    ElMessage.success('删除成功')
  })
}

onMounted(() => {
  // 加载数据
})
</script>

<style scoped lang="scss">
.menu-page {
  .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
}
</style>

